# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import pymysql

class CsgoPipeline:
    def open_spider(self,spider):
        self.con = pymysql.connect(host='10.30.59.136', port=3306, user='root', password='123456', database='wdr',
                                   charset='utf8')
        #self.cur = self.con.cursor()
    def close_spider(self,spider):
        self.con.close()
    def process_item(self, item, spider):
        self.cur = self.con.cursor()
        self.cur.execute(
            'insert into csgo (name,jia,c_jia,shu,z_jia,g_shu,mo,zhi,lei,qiang,q_name) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
            [item['name'], item['jia'], item['c_jia'], item['shu'], item['z_jia'], item['g_shu'], item['mo'],
             item['zhi'], item['lei'], item['qiang'], item['q_name']])
        self.cur = self.con.commit()

        return item